UpdateEventAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 29
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 21 2
1
import {
2
  Body,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Put,
8
  Param
9
} from '@nestjs/common';
10
import { AuthGuard } from '@nestjs/passport';
11
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
12
import { UpdateEventCommand } from 'src/Application/Calendar/Command/UpdateEventCommand';
13
import { ICommandBus } from 'src/Application/ICommandBus';
14
import { UserRole } from 'src/Domain/User/User.entity';
15
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
16
import { Roles } from 'src/Infrastructure/User/Decorator/Roles';
17
import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard';
18
import { EventDTO } from '../DTO/EventDTO';
19
20
@Controller('events')
21
@ApiTags('Calendar')
22
@ApiBearerAuth()
23
@UseGuards(AuthGuard('bearer'), RolesGuard)
24
export class UpdateEventAction {
25
  constructor(
26
    @Inject('ICommandBus')
27
    private readonly commandBus: ICommandBus
28
  ) {}
29
30
  @Put(':id')
31
  @Roles(UserRole.PHOTOGRAPHER)
32
  @ApiOperation({ summary: 'Update event' })
33
  public async index(@Param() { id }: IdDTO, @Body() dto: EventDTO) {
34
    try {
35
      const { date, schoolId, userId, summary } = dto;
36
37
      await this.commandBus.execute(
38
        new UpdateEventCommand(
39
          id,
40
          new Date(date),
41
          userId,
42
          schoolId,
43
          summary
44
        )
45
      );
46
47
      return { id };
48
    } catch (e) {
49
      throw new BadRequestException(e.message);
50
    }
51
  }
52
}
53